package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.entity.guang.BatteryInWarehouseEntity
import com.c.ctgproject.entity.guang.CarListEntity
import com.c.ctgproject.entity.guang.MaterialWarehouseHistoryEntity
import com.c.ctgproject.entity.guang.PowerBatteryOutEntity
import com.c.ctgproject.ui.collect.*
import com.c.ctgproject.utils.MyConstants
import com.c.ctgproject.utils.getGson
import com.c.ctgproject.utils.handlerNull
import com.c.ctgproject.utils.noDataHandler
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.textColorResource

class MaterialHistoryAdapter(private val context: Context, private val mList: List<MaterialWarehouseHistoryEntity.DataBean.ListBean>) : BaseEmptyRecyclerViewAdapterV2(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_material_history_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mNameTV.text = data.materialName.noDataHandler()
            holder.mKG.text = data.weightDiff.noDataHandler()
            holder.mPreKG.text = data.weightBefore.noDataHandler()
            holder.mLastKG.text = data.weightAfter.noDataHandler()
            holder.mPersonTV.text = data.createPersonName.noDataHandler()
            holder.mTimeTV.text = data.createTime.noDataHandler()
            val method = when (data.method) {
                1 -> "入库"
                2 -> "出库"
                3 -> "盘盈"
                4 -> "盘亏"
                else -> "暂无数据"
            }
            holder.mChangeTypeTV.text = method
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mNameTV: TextView = view.findViewById(R.id.mNameTV)
        val mKG: TextView = view.findViewById(R.id.mKG)
        val mPreKG: TextView = view.findViewById(R.id.mPreKG)
        val mLastKG: TextView = view.findViewById(R.id.mLastKG)
        val mTimeTV: TextView = view.findViewById(R.id.mTimeTV)
        val mPersonTV: TextView = view.findViewById(R.id.mPersonTV)
        val mChangeTypeTV: TextView = view.findViewById(R.id.mChangeTypeTV)
    }
}